package cn.xeblog.plugin.util;

import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.messages.AlertMessagesManager;
import javax.swing.Icon;

/**
 * 弹出消息工具类
 *
 * @author LYF
 * @date 2022-07-21
 */
public class AlertMessagesUtil {

  /**
   * 弹出普通对象框
   *
   * @param title   标题
   * @param message 消息
   */
  public static void showInfoDialog(String title, String message) {
    showMessageDialog(title, message, new String[]{"确定"}, Messages.getInformationIcon());
  }

  /**
   * 弹出警告对象框
   *
   * @param title   标题
   * @param message 消息
   */
  public static void showWarningDialog(String title, String message) {
    showMessageDialog(title, message, new String[]{"确定"}, Messages.getWarningIcon());
  }

  /**
   * 弹出错误对象框
   *
   * @param title   标题
   * @param message 消息
   */
  public static void showErrorDialog(String title, String message) {
    showMessageDialog(title, message, new String[]{"确定"}, Messages.getErrorIcon());
  }

  /**
   * 弹出确定(是/否)对象框
   *
   * @param title   标题
   * @param message 消息
   */
  public static boolean showYesNoDialog(String title, String message) {
    return showYesNoDialog(title, message, "确定", "取消");
  }

  /**
   * 弹出确定(是/否)对象框
   *
   * @param title   标题
   * @param message 消息
   * @param yesText yes文本
   * @param noText  no文本
   * @return
   */
  public static boolean showYesNoDialog(String title, String message, String yesText, String noText) {
    return AlertMessagesManager.instance().showYesNoDialog(title, message, yesText, noText, null,
        null, Messages.getQuestionIcon(), null);
  }

  /**
   * 弹出消息对象框
   *
   * @param title   标题
   * @param message 消息
   */
  public static void showMessageDialog(String title, String message, String[] options, Icon icon) {
    AlertMessagesManager.instance().showMessageDialog(null, null, message, title,
        options, 0, -1, icon, null, null);
  }
}
